package com.yan;

import com.rabbitmq.client.*;

/*
    消息消费者
 */
public class consumer01 {

    public static void main(String[] args) throws Exception {
        onePushMessage();
    }

    //等待 mq推消息
    private static void onePushMessage() {
        try {
            ConnectionFactory factory = new ConnectionFactory();
            //  指定虚拟主机('/' 代指这个服务器) 在url中的转义字符 %2f
            // 交换器协议://用户名:密码@ip:端口/虚拟主机
            factory.setUri("amqp://root:root@1.116.195.238:5672/%2f");
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();

            GetResponse getResponse = channel.basicGet(QueueConstants.defaultQueueName, true);
            System.out.println("111111111111111111   " + new String(getResponse.getBody(), "utf-8"));

            channel.close();
            connection.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
